package com.qiaofang.housewarehouse.facade.impl;

import com.qiaofang.housewarehouse.service.CityQueryService;
import com.qiaofang.housewarehouse.stub.constants.ResponseCode;
import com.qiaofang.housewarehouse.stub.facade.CityQueryFacade;
import com.qiaofang.housewarehouse.stub.request.CityDistricRequest;
import com.qiaofang.housewarehouse.stub.request.CityRegionRequest;
import com.qiaofang.housewarehouse.stub.response.CityDistricResponse;
import com.qiaofang.housewarehouse.stub.response.CityRegionResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 查询城市区域板块服务接口实现
 */
@RestController
public class CityQueryFacadeImpl implements CityQueryFacade {
    private static final  Logger logger = LoggerFactory.getLogger(CityQueryFacadeImpl.class);

    @Resource
    private CityQueryService cityQueryService;

    /**
     * 通过城市获取区域list
     *
     * @param cityRegionRequest
     * @return
     */
    @Override
    public CityRegionResponse listRegionByCity(@RequestBody @Valid CityRegionRequest cityRegionRequest) {
        CityRegionResponse response = new CityRegionResponse();
        try {
            response.setData(cityQueryService.listEntityCityByRow(cityRegionRequest.getCityName()));
            response.setResponseCode(ResponseCode.RC_SUCCESS.getResponseCode());
            response.setResponseMessage(ResponseCode.RC_SUCCESS.getResponseMessage());
        } catch (Exception e) {
            response.setResponseCode(ResponseCode.RC_EXCEPTION_ERROR.getResponseCode());
            response.setResponseMessage(ResponseCode.RC_EXCEPTION_ERROR.getResponseMessage());
            logger.error("CityQueryFacadeImpl error！", e);
        }
        return response;
    }
    /**
     * 查询区域下的板块list
     *
     * @param cityDistricRequest
     * @return
     */
    @Override
    public CityDistricResponse listDistricByRegion(@RequestBody @Valid CityDistricRequest cityDistricRequest) {
        CityDistricResponse response = new CityDistricResponse();
        try {
            response.setData(cityQueryService.listDistricCityByRow(cityDistricRequest.getCityName(), cityDistricRequest.getRegion()));
            response.setResponseCode(ResponseCode.RC_SUCCESS.getResponseCode());
            response.setResponseMessage(ResponseCode.RC_SUCCESS.getResponseMessage());
        } catch (Exception e) {
            response.setResponseCode(ResponseCode.RC_EXCEPTION_ERROR.getResponseCode());
            response.setResponseMessage(ResponseCode.RC_EXCEPTION_ERROR.getResponseMessage());
            logger.error("CityQueryFacadeImpl error！", e);
        }
        return response;
    }
}
